﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MbUnit.Framework;
using Frost;
using Rhino.Mocks;

namespace Frost.Tests.Setup_Test_Run_Specs {

    [TestFixture]
    public class when_test_execution_service_sets_up_test_run : with_test_execution_service {
        protected override void Because_of() {
            _testRepository.Stub(x => x.GetTests()).Return(new List<ITest>());
            _emptyRunner.SetupTestRun();
        
        }
        [Test]
        public void should_request_all_tests_from_repository() {
            _testRepository.AssertWasCalled(x => x.GetTests());
        }
        [Test]
        public void should_retrieve_files_for_test() {
            _emptyRunner.Tests.ShouldNotBeNull();
        }

    }

    [TestFixture]
    public class when_runner_is_running_tests : with_test_execution_service{
        ITest test1;
        ITest test2;
        ITestStrategy strategy;
        protected override void Because_of() {
            test1 = new NullTest { Name = "Test1" };
            test2 = new NullTest { Name = "Test2" };
            strategy = MockRepository.GenerateStub<ITestStrategy>();
            _testRepository.Stub(x => x.GetTests()).Return(new List<ITest> {
                test1, 
                test2
            });
            _strategyService.Stub(x => x.GetTestStrategy(null))
                .IgnoreArguments()
                .Return(strategy);

            _emptyRunner.SetupTestRun();
            _emptyRunner.RunTests();
        }
        [Test]
        public void should_request_strategy_for_test() {
            _strategyService.AssertWasCalled(x => x.GetTestStrategy(test1));
            _strategyService.AssertWasCalled(x => x.GetTestStrategy(test2));
        }
        [Test]
        public void should_ask_strategy_to_run_the_test() {
            strategy.AssertWasCalled(x => x.RunTest(test1));
            strategy.AssertWasCalled(x => x.RunTest(test2));
        }
    }

    public abstract class with_test_execution_service {
        public TestRunner _emptyRunner;
        public ITestRepository _testRepository;
        public ITestStrategyService _strategyService;
        public ITestEnvironment _testEnvironment;
        
        [SetUp]
        public void Setup() {
            _testRepository = MockRepository.GenerateStub<ITestRepository>();
            _strategyService = MockRepository.GenerateStub<ITestStrategyService>();
            _testEnvironment = MockRepository.GenerateStub<ITestEnvironment>();
            
            _emptyRunner = new TestRunner(_testRepository, 
                _strategyService, 
                _testEnvironment);
            
            
            Because_of();
        }

        protected abstract void Because_of();
    }
}
